package tzh;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class AppReflect {
    public static void main(String[] args) throws Exception{
        Class<?> A = Class.forName("tzh.Animal");
        Object o = A.newInstance();
        Field[] fields = A.getDeclaredFields();
        for(Field field : fields){
            field.setAccessible(true);
            Class<?> type = field.getType();
            if(type.toString().endsWith("String")){
                field.set(o,"Ash");
            }else if(type.toString().endsWith("Integer")){
                field.set(o,2);
            }else if(type.toString().endsWith("Double")) {
                field.set(o, 2.5);
            }
        }
        Method say = A.getDeclaredMethod("say");
        Object a = say.invoke(o);
    }
}
